package com.lanou.dllo.findfood.adpter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.lanou.dllo.findfood.R;
import com.lanou.dllo.findfood.entity.NewList;
import com.lanou.dllo.findfood.volley.VolleySington;

import java.util.List;

/**
 * Created by dllo on 15/10/26.
 */

    public class NewsRecyerAdpter extends RecyclerView.Adapter<NewsRecyerAdpter.RecyerAdpter>{
      private   List<NewList> lists ;

        public   void   addData( List<NewList> list){
            lists = list;
            notifyDataSetChanged();
        }

        @Override
        public RecyerAdpter onCreateViewHolder(ViewGroup parent, int viewType) {
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            View view = inflater.inflate(R.layout.recy_news_item,null);

            return new RecyerAdpter(view);
        }

        @Override
        public void onBindViewHolder(RecyerAdpter holder, int position) {

            if (lists != null && lists.size() > 0){
                NewList list = lists.get(position);
                holder.spfooddisption.setText(list.getDescription());
                holder.spfoodTitle.setText(list.getTitle());
                holder.spuserName.setText(list.getAccount().getNickname());
               // holder.praisescore.setText(list.getPraise_score());
              //  holder.parise.setText(list.getPraise());

//美食照片
                String imge = list.getImage();
                getBitmap(imge,holder.spfoodImage);
//美食发表者
                String avater=list.getAccount().getAvatar();
                getBitmap(avater,holder.speuserimge);
//美食评论者




//                holder.praAvater.setText(list.getPraise_member().get(0).getNickname());
//                String url = list.getPraise_member().get(0).getAvatar();
//                getBitmap(url,holder.spnikAvater);


                //



            }
            holder.position= position;
        }
        private void getBitmap(String url, final NetworkImageView networkImageView) {
            ImageLoader imageLoader = VolleySington.getInstance().getImageLoader();
            networkImageView.setDefaultImageResId(R.mipmap.ic_launcher);
            networkImageView.setErrorImageResId(R.mipmap.ic_launcher);
            networkImageView.setImageUrl(url, imageLoader);


        }





        @Override
        public int getItemCount() {
            return lists!= null && lists.size()>0 ? lists.size():0;
        }

        class RecyerAdpter extends RecyclerView.ViewHolder{
            private NetworkImageView speuserimge,spfoodImage,spnikAvater;
            private TextView spuserName,praisescore,spfoodTitle,spfooddisption,parise,praAvater;
            private int position;

            public RecyerAdpter(View itemView) {
                super(itemView);
                speuserimge = (NetworkImageView) itemView.findViewById(R.id.Newuserimge);

                spfooddisption = (TextView) itemView.findViewById(R.id.Newfooddisption);

                spfoodImage = (NetworkImageView) itemView.findViewById(R.id.NewfoodImage);

                spuserName = (TextView) itemView.findViewById(R.id.NewuserName);

                spfoodTitle = (TextView) itemView.findViewById(R.id.NewfoodTitle);
                spfooddisption = (TextView) itemView.findViewById(R.id.Newfooddisption);
                parise = (TextView) itemView.findViewById(R.id.Newparise);






            }
        }
    }


